﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.util {
    import Engine.Classes.*;
    import Engine.Managers.*;
    import Engine.Init.*;
    import Engine.*;

    public class Sounds {

        public static const SET_MONEY:String = "set_money";
        public static const SET_HARVEST:String = "set_harvest";
        public static const SET_PLANT:String = "set_plant";
        public static const SET_CLICK:String = "set_click";
        public static const SET_SHEEP:String = "set_sheep";
        public static const SET_FANFARE:String = "set_fanfare";
        public static const SET_BUILDING_CONSTRUCTION:String = "set_construction";
        public static const SET_CHEERING:String = "set_cheering";
        public static const LOOPING:int = 999999;
        protected static const ALL_SETS:Object = {
            set_forceLoad:{ANY:["click2", "doober_drop", "bonus_ramp_1", "bonus_ramp_2", "bonus_ramp_3", "bonus_ramp_4", "bonus_ramp_5", "bonus_ramp_6", "doober_coin_click", "doober_xp_click", "doober_energy_click", "doober_food_click", "doober_population_click", "place_building", "building_construct1", "train_leaves", "train_arrives", "train_moving", "train_unload", "doorbell1", "doorbell2", "knock1", "knock2", "knock3", "lumberjack", "peopleMoveIn", "tourbus_start", "tourbus_engine_loop", "tourbus_stop", "tourbus_honk", "sfx_fanfare1", "arrest", "siren", "moneybag", "helicopter"]},
            set_money:{ANY:["money1", "money2", "money3"]},
            set_harvest:{
                Residence:["knock1", "knock2", "knock3", "doorbell1", "doorbell2"],
                Business:["harvest1", "harvest2", "harvest3"],
                ANY:["harvest1", "harvest2", "harvest3"]
            },
            set_plant:{ANY:["plant_plot_1", "plant_plot_2", "plant_plot_3"]},
            set_click:{ANY:["UI_click1", "UI_click2", "UI_click3"]},
            set_sheep:{ANY:["sfx_sheep1", "sfx_sheep2", "sfx_sheep3"]},
            set_fanfare:{ANY:["sfx_fanfare1"]},
            set_construction:{ANY:["building_construct1"]},
            set_cheering:{ANY:["cheering1", "cheering2", "cheering3", "cheering4"]}
        };
        protected static const ALL_SOUNDS:Object = {
            money1:"assets/sounds/actions/sfx_receive_coins_01.mp3",
            money2:"assets/sounds/actions/sfx_receive_coins_02.mp3",
            money3:"assets/sounds/actions/sfx_receive_coins_03.mp3",
            harvest1:"assets/sounds/city_sounds/harvest/sfx_harvest_crop_01.mp3",
            harvest2:"assets/sounds/city_sounds/harvest/sfx_harvest_crop_02.mp3",
            harvest3:"assets/sounds/city_sounds/harvest/sfx_harvest_crop_03.mp3",
            doorbell1:"assets/sounds/city_sounds/harvest_houses/sfx_doorbell1.mp3",
            doorbell2:"assets/sounds/city_sounds/harvest_houses/sfx_doorbell2.mp3",
            knock1:"assets/sounds/city_sounds/harvest_houses/sfx_knock1.mp3",
            knock2:"assets/sounds/city_sounds/harvest_houses/sfx_knock2.mp3",
            knock3:"assets/sounds/city_sounds/harvest_houses/sfx_knock3.mp3",
            plant_plot_1:"assets/sounds/city_sounds/plant/sfx_plant_01.mp3",
            plant_plot_2:"assets/sounds/city_sounds/plant/sfx_plant_02.mp3",
            plant_plot_3:"assets/sounds/city_sounds/plant/sfx_plant_03.mp3",
            ship_leaves:"assets/sounds/city_sounds/ship/sfx_ship_leaves_dock.mp3",
            ship_approaches:"assets/sounds/city_sounds/ship/sfx_ship_docking.mp3",
            ship_sailing:"assets/sounds/city_sounds/ship/sfx_ship_moving_through_water_loop.mp3",
            ships_unlocked:"assets/sounds/city_sounds/ship/sfx_ship_you_can_now_use_ships.mp3",
            ships_unloaded:"assets/sounds/city_sounds/ship/sfx_ship_receiving_payload.mp3",
            truck_start:"assets/sounds/city_sounds/truck_sfx/sfx_truck_start.mp3",
            truck_engine_loop:"assets/sounds/city_sounds/truck_sfx/sfx_truck_engine_loop.mp3",
            truck_off:"assets/sounds/city_sounds/truck_sfx/sfx_truck_off.mp3",
            truck_honk:"assets/sounds/city_sounds/truck_sfx/sfx_horn_honkhonk.mp3",
            train_leaves:"assets/sounds/city_sounds/train/sfx_train_leaves.mp3",
            train_arrives:"assets/sounds/city_sounds/train/sfx_train_arrives.mp3",
            train_moving:"assets/sounds/city_sounds/train/sfx_train_moving_loop.mp3",
            train_unload:"assets/sounds/city_sounds/train/sfx_train_food_delivered.mp3",
            place_building:"assets/sounds/city_sounds/construction/sfx_place_building.mp3",
            building_construct1:"assets/sounds/city_sounds/construction/sfx_building_construct1.mp3",
            lumberjack:"assets/sounds/city_sounds/lumberjack/sfx_chop_tree.mp3",
            land_expand:"assets/sounds/city_sounds/expand/sfx_land_expand.mp3",
            sfx_sheep1:"assets/sounds/city_sounds/animals/sfx_sheep_1_01.mp3",
            sfx_sheep2:"assets/sounds/city_sounds/animals/sfx_sheep_1_02.mp3",
            sfx_sheep3:"assets/sounds/city_sounds/animals/sfx_sheep_1_03.mp3",
            sfx_chicken1:"assets/sounds/city_sounds/animals/sfx_chicken_01.mp3",
            sfx_chicken2:"assets/sounds/city_sounds/animals/sfx_chicken_02.mp3",
            sfx_chicken3:"assets/sounds/city_sounds/animals/sfx_chicken_03.mp3",
            sfx_cow1:"assets/sounds/city_sounds/animals/sfx_cow_01.mp3",
            sfx_cow2:"assets/sounds/city_sounds/animals/sfx_cow_02.mp3",
            sfx_cow3:"assets/sounds/city_sounds/animals/sfx_cow_03.mp3",
            sfx_goat1:"assets/sounds/city_sounds/animals/sfx_goat_01.mp3",
            sfx_goat2:"assets/sounds/city_sounds/animals/sfx_goat_02.mp3",
            sfx_goat3:"assets/sounds/city_sounds/animals/sfx_goat_03.mp3",
            neighbor:"assets/sounds/ui/sfx_ui_neighbor.mp3",
            dialogSpawn:"assets/sounds/ui/sfx_ui_dialog_show.mp3",
            dialogClose:"assets/sounds/ui/sfx_ui_dialog_hide.mp3",
            expandMenu:"assets/sounds/ui/sfx_ui_expand_menu.mp3",
            UI_click1:"assets/sounds/ui/sfx_ui_click_1.mp3",
            UI_click2:"assets/sounds/ui/sfx_ui_click_2.mp3",
            UI_click3:"assets/sounds/ui/sfx_ui_click_3.mp3",
            UI_mouseover:"assets/sounds/ui/sfx_ui_mouseover.mp3",
            UI_expandmenu:"assets/sounds/ui/sfx_ui_expand_menu.mp3",
            click1:"assets/sounds/city_sounds/clicks/sfx_click_1.mp3",
            click2:"assets/sounds/city_sounds/clicks/sfx_click_2.mp3",
            click3:"assets/sounds/city_sounds/clicks/sfx_click_3.mp3",
            click4:"assets/sounds/city_sounds/clicks/sfx_click_4.mp3",
            click5:"assets/sounds/city_sounds/clicks/sfx_click_5.mp3",
            tourbus_start:"assets/sounds/city_sounds/tourbus/sfx_tourbus_start.mp3",
            tourbus_engine_loop:"assets/sounds/city_sounds/tourbus/sfx_tourbus_loop.mp3",
            tourbus_stop:"assets/sounds/city_sounds/tourbus/sfx_tourbus_stop.mp3",
            tourbus_honk:"assets/sounds/city_sounds/tourbus/sfx_tourbus_horn.mp3",
            doober_drop:"assets/sounds/city_sounds/doobers/doober_drop_01.mp3",
            bonus_ramp_1:"assets/sounds/city_sounds/doobers/bonus_ramp_01.mp3",
            bonus_ramp_2:"assets/sounds/city_sounds/doobers/bonus_ramp_02.mp3",
            bonus_ramp_3:"assets/sounds/city_sounds/doobers/bonus_ramp_03.mp3",
            bonus_ramp_4:"assets/sounds/city_sounds/doobers/bonus_ramp_04.mp3",
            bonus_ramp_5:"assets/sounds/city_sounds/doobers/bonus_ramp_05.mp3",
            bonus_ramp_6:"assets/sounds/city_sounds/doobers/bonus_ramp_06.mp3",
            doober_coin_click:"assets/sounds/city_sounds/doobers/doober_collect_coins.mp3",
            doober_xp_click:"assets/sounds/city_sounds/doobers/doober_collect_xp.mp3",
            doober_energy_click:"assets/sounds/city_sounds/doobers/doober_collect_energy.mp3",
            doober_food_click:"assets/sounds/city_sounds/doobers/doober_collect_food.mp3",
            doober_reputation_click:"assets/sounds/city_sounds/doobers/doober_reputation.mp3",
            doober_collectable_click:"assets/sounds/city_sounds/doobers/doober_collect_collectionitem.mp3",
            doober_population_click:"assets/sounds/city_sounds/doobers/doober_collect_population.mp3",
            collection_completed:"assets/sounds/city_sounds/collections/sfx_collection_completed.mp3",
            poof:"assets/sounds/city_sounds/effects/poof.mp3",
            speedup:"assets/sounds/city_sounds/reward_sfx/sfx_reward_5.mp3",
            Collect:"assets/sounds/franchise/completion_dialog.mp3",
            Remind:"assets/sounds/franchise/green_yes.mp3",
            sfx_fanfare1:"assets/sounds/city_sounds/grand_opening/sfx_grand_opening.mp3",
            cheering1:"assets/sounds/city_sounds/cheering/sfx_group_of_05.mp3",
            cheering2:"assets/sounds/city_sounds/cheering/sfx_group_of_10.mp3",
            cheering3:"assets/sounds/city_sounds/cheering/sfx_group_of_15.mp3",
            cheering4:"assets/sounds/city_sounds/cheering/sfx_group_of_20.mp3",
            peopleMoveIn:"assets/sounds/city_sounds/npcs/sfx_people_move-in.mp3",
            unwrap:"assets/sounds/city_sounds/unwrap/unwrap_small.mp3",
            collectionComplete:"assets/sounds/city_sounds/collections/sfx_collection_completed.mp3",
            arrest:"assets/sounds/copsnbandits/whistle.mp3",
            siren:"assets/sounds/copsnbandits/siren.mp3",
            moneybag:"assets/sounds/copsnbandits/moneybag.mp3",
            helicopter:"assets/sounds/copsnbandits/helicopter4.mp3",
            cruise_arrive:"assets/sounds/city_sounds/ship/cruise_ship_arrive2.mp3",
            cruise_arrive_nocamera:"assets/sounds/city_sounds/ship/cruise_ship_arrive_no_camera.mp3",
            cruise_fireworks:"assets/sounds/city_sounds/ship/fireworks.mp3"
        };

        public static var infiniteLoopingSounds:Array = [];
        private static var doneInit:Boolean = false;
        private static var musicObject:SoundObjectWrapper = null;
        private static var musicStarted:Boolean = false;
        private static var donePostLoad:Boolean = false;

        public static function setSoundManagerSFXMute():void{
            var _local1:Boolean = Global.player.options["sfxDisabled"];
            if (_local1){
                SoundManager.mute();
            } else {
                SoundManager.unmute();
            };
        }
        public static function setSoundManagerMusicMute():void{
            var _local1:Boolean = Global.player.isMusicDisabled();
            if (_local1){
                pauseMusic();
            } else {
                unpauseMusic();
            };
        }
        public static function isMusicEnabled():Boolean{
            return (!(Global.player.isMusicDisabled()));
        }
        public static function pauseMusic():void{
            musicObject.pause();
        }
        public static function unpauseMusic():void{
            if (((isMusicEnabled()) && (InitializationManager.getInstance().haveAllCompleted()))){
                if (musicStarted){
                    musicObject.unpause();
                } else {
                    musicStarted = true;
                    musicObject.play(0, LOOPING, null, true);
                };
            };
        }
        public static function init():void{
            if (doneInit){
                return;
            };
            var _local1:Boolean;
            if (isMusicEnabled()){
                _local1 = false;
                StatsManager.count("music_enabled");
            };
            musicObject = new SoundObjectWrapper("bgMusic", Global.getAssetURL(Global.gameSettings.getString("backgroundMusicUrl")), _local1);
            setSoundManagerSFXMute();
            setSoundManagerMusicMute();
            doneInit = true;
        }
        public static function startPostloading():void{
            if (donePostLoad){
                return;
            };
            var _local1:BundleLoader = new BundleLoader("assets/bundle/sound.swf");
            _local1.load(null);
            donePostLoad = true;
        }
        public static function loadSoundByName(_arg1:String):void{
            var _local2:String = ALL_SOUNDS[_arg1];
            SoundManager.addSound(_arg1, Global.getAssetURL(_local2), false);
        }
        public static function play(_arg1:String, _arg2:Number=0, _arg3:int=0):SoundObject{
            var _local4:SoundObject;
            var _local5:String;
            if (SoundManager.getSoundById(_arg1) != null){
                _local4 = SoundManager.playSound(_arg1, _arg2, _arg3);
                if (_arg3 == Sounds.LOOPING){
                    Sounds.infiniteLoopingSounds.push(_local4);
                };
                return (_local4);
            };
            _local5 = ALL_SOUNDS[_arg1];
            if (_local5 != null){
                SoundManager.addSound(_arg1, Global.getAssetURL(_local5), false);
                _local4 = SoundManager.playSound(_arg1, _arg2, _arg3);
                if (_arg3 == Sounds.LOOPING){
                    Sounds.infiniteLoopingSounds.push(_local4);
                };
                return (_local4);
            };
            throw (new Error(("Sound not registered in Sounds.as: " + _arg1)));
        }
        public static function playSoundFromArray(_arg1:Array, _arg2:Number=0, _arg3:int=0):void{
            Sounds.play(MathUtil.randomElement(_arg1), _arg2, _arg3);
        }
        public static function stop(_arg1):void{
            if (!_arg1){
                return;
            };
            if ((((_arg1 is String)) && (!((SoundManager.getSoundById(_arg1) == null))))){
                SoundManager.stopSound(_arg1);
            } else {
                if ((_arg1 is SoundObject)){
                    (_arg1 as SoundObject).stop();
                };
            };
        }
        public static function playFromSet(_arg1:String, _arg2:SavedObject=null):void{
            var _local3:Object = ALL_SETS[_arg1];
            if (_local3 == null){
                ErrorManager.addError(("Error playing sounds, unknown set name: " + _arg1));
                return;
            };
            var _local4:String = ((_arg2)!=null) ? _arg2.getClassName() : "ANY";
            var _local5:Array = (ALL_SETS[_arg1][_local4] as Array);
            if (_local5 == null){
                _local5 = (ALL_SETS[_arg1]["ANY"] as Array);
            };
            if ((((_local5 == null)) || ((_local5.length == 0)))){
                ErrorManager.addError(((("Error playing sounds, bad definition for set: " + _arg1) + ", target: ") + _local4));
                return;
            };
            Sounds.play(MathUtil.randomElement(_local5));
        }
        public static function stopAnyLoopingSounds():void{
            var _local1:String;
            var _local2:SoundObject;
            for each (_local1 in ["tourbus_engine_loop", "ship_sailing", "train_moving"]) {
                Sounds.stop(_local1);
            };
            for each (_local2 in Sounds.infiniteLoopingSounds) {
                Sounds.stop(_local2);
            };
            Sounds.infiniteLoopingSounds = [];
        }

    }
}//package Classes.util 
